package com.itheima.redbaby.engine.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.alibaba.fastjson.JSONObject;
import com.itheima.redbaby.ContantValue;
import com.itheima.redbaby.bean.Product;
import com.itheima.redbaby.bean.Topic;
import com.itheima.redbaby.engine.BaseEngine;
import com.itheima.redbaby.engine.TopicEngine;
import com.itheima.redbaby.engine.TopicServletPListEngine;
import com.itheima.redbaby.factory.DaoAndEngineFactory;

public class TopicServletPListEngineImpl extends BaseEngine implements
		TopicServletPListEngine {

	@Override
	public List<Product> getTopicPList(String id, int page, int pageNum) {

		// 存放请求参数的map
		Map<String, Object> requestParams = new HashMap<String, Object>();
		requestParams.put("page", page);// 1 2
		requestParams.put("pageNum", pageNum);
		requestParams.put("id", id);
		// 获得服务器返回的 json 对象

		JSONObject json = getJson(TYPE_GET,
				ContantValue.REDBOY_TopicServletPList, requestParams);

		List<Product> topicList = JSONObject.parseArray(
				json.getString("productlist"), Product.class);

		for (Product product : topicList) {
			System.out.println(product.toString());
		}

		return topicList;

	}

}
